<?
include("./_common.php");
include("$g4[path]/lib/shop.lib.php");

if(!$excel_sql || $excel_sql=="")
{
	echo("<script>alert('잘못된 접속입니다.');history.back(-1);</script>");
}
else
{
	$f_name = "주문현황(".date("Ymd").").xls";

	header( "Content-type: application/vnd.ms-excel; charset=ks_c_5601-1987");
	header( "Content-Disposition: attachment; filename=$f_name");
	header( "Content-Description: PHP4 Generated Data");


	$order_rst = mysql_query(stripslashes($excel_sql));
	$BODY = "";
	$BODY.= "<table>";
	$BODY.= "<tr>";
	$BODY.= "<td>순번</td>";
	$BODY.= "<td>주문일자</td>";
	$BODY.= "<td>상태</td>";
	$BODY.= "<td>주문번호</td>";
	$BODY.= "<td>주문제목</td>";
	$BODY.= "<td>주문구분</td>";
	$BODY.= "<td>주문자ID</td>";
	$BODY.= "<td>주문자명</td>";
	$BODY.= "<td>주문자E-mail</td>";
	$BODY.= "<td>주문자 전화번호</td>";
	$BODY.= "<td>주문자 휴대폰</td>";
	$BODY.= "<td>주문자 우편번호</td>";
	$BODY.= "<td>주문자 주소</td>";
	$BODY.= "<td>주문자 상세주소</td>";
	$BODY.= "<td>상품코드</td>";
	$BODY.= "<td>상품명</td>";
	$BODY.= "<td>수량</td>";
	$BODY.= "<td>단가</td>";
	$BODY.= "<td>합계금액</td>";
	$BODY.= "<td>배송비</td>";
	$BODY.= "<td>포인트결제</td>";
	$BODY.= "<td>결제금액</td>";
	$BODY.= "<td>결제방법</td>";
	$BODY.= "<td>결제정보</td>";
	$BODY.= "<td>수령자명</td>";
	$BODY.= "<td>수령자E-mail</td>";
	$BODY.= "<td>수령자 전화번호</td>";
	$BODY.= "<td>수령자 휴대폰</td>";
	$BODY.= "<td>수령자 우편번호</td>";
	$BODY.= "<td>수령자 주소</td>";
	$BODY.= "<td>수령자 상세주소</td>";
	$BODY.= "<td>요구사항</td>";
	$BODY.= "<td>택배사</td>";
	$BODY.= "<td>송장번호</td>";
	$BODY.= "</tr>";
	$order_no = 1;
	while($order_row = mysql_fetch_array($order_rst))
	{
		$order_goods_sql = "select * from g4_order_goods where oid = '".$order_row[oid]."' order by idx asc";
		$order_goods_rst = mysql_query($order_goods_sql);
		while($order_goods = mysql_fetch_array($order_goods_rst))
		{
			$BODY.= "<tr>";
			$BODY.= "<td>".$order_no."</td>";
			$BODY.= "<td>".$order_row[buy_datetime]."</td>";
			$BODY.= "<td>".get_status($order_row[status])."</td>";
			$BODY.= "<td>".$order_row[oid]."</td>";
			$BODY.= "<td>".$order_row[o_subject]."</td>";
			$BODY.= "<td>".$order_row[mb_part]."</td>";
			$BODY.= "<td>".$order_row[mb_id]."</td>";
			$BODY.= "<td>".$order_row[o_name]."</td>";
			$BODY.= "<td>".$order_row[o_email]."</td>";
			$BODY.= "<td>".$order_row[o_tel]."</td>";
			$BODY.= "<td>".$order_row[o_hp]."</td>";
			$BODY.= "<td>".$order_row[o_zip]."</td>";
			$BODY.= "<td>".$order_row[o_addr1]."</td>";
			$BODY.= "<td>".$order_row[o_addr2]."</td>";
			$BODY.= "<td>".$order_goods[g_code]."</td>";
			$BODY.= "<td>".$order_goods[g_name]."</td>";
			$BODY.= "<td>".$order_goods[cnt]."</td>";
			$BODY.= "<td>".$order_goods[g_price]."</td>";
			$BODY.= "<td>".$order_goods[tot_price]."</td>";
			$BODY.= "<td>".$order_row[pay_tranc]."</td>";
			$BODY.= "<td>".$order_row[pay_point]."</td>";
			$BODY.= "<td>".$order_row[pay_amount]."</td>";
			$BODY.= "<td>".get_paymethod($order_row[pay_method])."</td>";
			$BODY.= "<td>".$order_row[pay_info]."</td>";
			$BODY.= "<td>".$order_row[s_name]."</td>";
			$BODY.= "<td>".$order_row[s_email]."</td>";
			$BODY.= "<td>".$order_row[s_tel]."</td>";
			$BODY.= "<td>".$order_row[s_hp]."</td>";
			$BODY.= "<td>".$order_row[s_zip]."</td>";
			$BODY.= "<td>".$order_row[s_addr1]."</td>";
			$BODY.= "<td>".$order_row[s_addr2]."</td>";
			$BODY.= "<td>".$order_row[s_memo]."</td>";
			$BODY.= "<td>".$order_row[tranc]."</td>";
			$BODY.= "<td>".$order_row[tranc_num]."</td>";
			$BODY.= "</tr>";

			$order_no++;
		}

	}
	$BODY.= "</table>";

	echo($BODY);
}
?>